import React from 'react';
import {
  View,
  StyleSheet,
  SafeAreaView,
  ScrollView,
} from 'react-native';
import { 
  Cell, 
  CellGroup, 
  Button, 
  Grid, 
  GridItem, 
  Card,
  Tag,
  Avatar,
  Divider 
} from 'tdesign-mobile-react';

const HomeScreen = ({ navigation }) => {
  const quickActions = [
    { icon: 'location', label: '附近景点', color: '#0052d9' },
    { icon: 'calendar', label: '行程规划', color: '#00a870' },
    { icon: 'user-group', label: '结伴出行', color: '#ed7b2f' },
    { icon: 'discount', label: '优惠活动', color: '#e34d59' },
  ];

  const recommendedTrips = [
    { id: 1, title: '三亚海滨度假', days: 3, price: '¥1299', image: '🏖️' },
    { id: 2, title: '北京文化之旅', days: 5, price: '¥2199', image: '🏛️' },
    { id: 3, title: '成都美食探索', days: 4, price: '¥1599', image: '🍜' },
  ];

  return (
    <SafeAreaView style={styles.container}>
      <ScrollView style={styles.scrollView}>
        {/* 用户信息卡片 */}
        <Card style={styles.userCard}>
          <View style={styles.userInfo}>
            <Avatar size="large" image="👤" />
            <View style={styles.userText}>
              <View style={styles.greeting}>
                <Tag theme="primary" variant="light">欢迎回来</Tag>
              </View>
              <View style={styles.userName}>探索更多精彩旅程</View>
            </View>
          </View>
        </Card>

        {/* 快捷操作 */}
        <CellGroup title="快捷操作" style={styles.section}>
          <Grid column={4} border={false}>
            {quickActions.map((action, index) => (
              <GridItem key={index} style={styles.gridItem}>
                <View style={[styles.actionIcon, { backgroundColor: action.color }]}>
                  <View style={styles.iconText}>{action.icon}</View>
                </View>
                <View style={styles.actionLabel}>{action.label}</View>
              </GridItem>
            ))}
          </Grid>
        </CellGroup>

        <Divider />

        {/* 推荐行程 */}
        <CellGroup title="推荐行程" style={styles.section}>
          {recommendedTrips.map((trip) => (
            <Cell
              key={trip.id}
              title={trip.title}
              description={`${trip.days}天 · ${trip.price}`}
              leftIcon={<View style={styles.tripIcon}>{trip.image}</View>}
              arrow
              onClick={() => console.log('查看行程:', trip.title)}
            />
          ))}
        </CellGroup>

        <Divider />

        {/* 操作按钮 */}
        <View style={styles.buttonSection}>
          <Button 
            theme="primary" 
            size="large" 
            style={styles.button}
            onClick={() => console.log('开始规划行程')}
          >
            开始规划行程
          </Button>
          <Button 
            theme="default" 
            size="large" 
            style={styles.button}
            onClick={() => console.log('浏览更多')}
          >
            浏览更多
          </Button>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#f5f5f5',
  },
  scrollView: {
    flex: 1,
  },
  userCard: {
    margin: 16,
    padding: 16,
    borderRadius: 12,
  },
  userInfo: {
    flexDirection: 'row',
    alignItems: 'center',
  },
  userText: {
    marginLeft: 12,
    flex: 1,
  },
  greeting: {
    marginBottom: 4,
  },
  userName: {
    fontSize: 16,
    fontWeight: '500',
    color: '#333',
  },
  section: {
    marginHorizontal: 16,
    marginVertical: 8,
  },
  gridItem: {
    alignItems: 'center',
    paddingVertical: 16,
  },
  actionIcon: {
    width: 48,
    height: 48,
    borderRadius: 24,
    alignItems: 'center',
    justifyContent: 'center',
    marginBottom: 8,
  },
  iconText: {
    fontSize: 20,
    color: '#fff',
  },
  actionLabel: {
    fontSize: 12,
    color: '#666',
    textAlign: 'center',
  },
  tripIcon: {
    fontSize: 24,
    width: 40,
    height: 40,
    textAlign: 'center',
    lineHeight: 40,
  },
  buttonSection: {
    padding: 16,
    gap: 12,
  },
  button: {
    marginBottom: 8,
  },
});

export default HomeScreen;